load("//bazel:ray.bzl", "ray_cc_library", "ray_cc_test")

ray_cc_library(
    name = "stats_metric",
    srcs = [
        "metric.cc",
        "metric_defs.cc",
        "tag_defs.cc",
    ],
    hdrs = [
        "metric.h",
        "metric_defs.h",
        "tag_defs.h",
    ],
    deps = [
        "//src/ray/util",
        "//src/ray/util:logging",
        "//src/ray/util:size_literals",
        "//src/ray/common:ray_config",
        "//src/ray/telemetry:open_telemetry_metric_recorder",
        "@com_github_jupp0r_prometheus_cpp//pull",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_prod",
        "@io_opencensus_cpp//opencensus/stats",
        "@io_opencensus_cpp//opencensus/tags",
    ],
)

ray_cc_library(
    name = "stats_lib",
    srcs = [
        "metric_exporter.cc",
    ],
    hdrs = [
        "metric.h",
        "metric_exporter.h",
        "stats.h",
        "tag_defs.h",
    ],
    linkopts = select({
        "@platforms//os:windows": [
        ],
        "//conditions:default": [
            "-lpthread",
        ],
    }),
    deps = [
        ":stats_metric",
        "//:reporter_rpc",
        "//src/ray/util:size_literals",
        "@com_github_grpc_grpc//:grpc_opencensus_plugin",
    ],
)

ray_cc_test(
    name = "stats_test",
    size = "small",
    srcs = ["stats_test.cc"],
    tags = [
        "no_tsan",
        "stats",
        "team:core",
    ],
    deps = [
        ":stats_lib",
        "@com_google_googletest//:gtest_main",
    ],
)

ray_cc_test(
    name = "metric_exporter_grpc_test",
    size = "small",
    srcs = [
        "metric_exporter_grpc_test.cc",
    ],
    tags = [
        "stats",
        "team:core",
    ],
    deps = [
        ":stats_lib",
        "@com_google_googletest//:gtest_main",
    ],
)
